package com.aliyun.heiyu.powermaster.server.rotary.service.impl;

import com.aliyun.heiyu.powermaster.proto.AlgorithmsRequest;
import com.aliyun.heiyu.powermaster.proto.CFDReply;
import com.aliyun.heiyu.powermaster.proto.CFDScale;
import com.aliyun.heiyu.powermaster.server.Error;
import com.aliyun.heiyu.powermaster.server.rotary.dao.CfdDAO;
import com.aliyun.heiyu.powermaster.server.rotary.dao.impl.CfdDAOImpl;
import com.aliyun.heiyu.powermaster.server.rotary.object.entity.DataCfdEntity;
import com.aliyun.heiyu.powermaster.server.rotary.service.CfdService;

/**
 * @Description  cfd数据实现类
 * @Author shun.zhang
 * @Date 2020/11/30 16:53
 **/
public class CfdServiceImpl implements CfdService {
    private CfdDAO cfdDAO;
    
    public CfdServiceImpl(){
        cfdDAO = new CfdDAOImpl();
    }
    /**
     * 获取cfd数据
     *
     * @param request
     * @return
     */
    @Override
    public CFDReply queryCfd(AlgorithmsRequest request) {
        CFDReply.Builder builder = CFDReply.newBuilder();
        CFDScale.Builder data = CFDScale.newBuilder();
        DataCfdEntity dataCfdEntity = cfdDAO.selectCfdNew();
        if(null == dataCfdEntity){
            return builder.setErrCode(Error.SUCCESS.getCode())
                .setErrMsg(Error.SUCCESS.getMessage())
                .setData(data)
                .build();
        }
        data.setCfdAcTempRange(dataCfdEntity.getCfd_ac_temp_range());
        data.setCfdDataRate(dataCfdEntity.getCfd_data_rate());
        data.setCfdDataSize(dataCfdEntity.getCfd_data_size());
        data.setCfdPer(dataCfdEntity.getCfd_per());
        data.setCfdSerPowerRange(dataCfdEntity.getCfd_ser_power_range());
        data.setRawAcTempRange(dataCfdEntity.getCfd_ac_temp_range());
        data.setRawDataRate(dataCfdEntity.getRaw_data_rate());
        data.setRawDataSize(dataCfdEntity.getRaw_data_size());
        data.setRawPer(dataCfdEntity.getRaw_per());
        data.setRawSerPowerRange(dataCfdEntity.getRaw_ser_power_range());
        builder.setData(data);
        return builder.build();
    }
}
